package com.yangzc.lion.sys.util;

import java.util.ArrayList;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import com.yangzc.lion.sys.organization.model.SysOrgPerson;
import com.yangzc.lion.sys.security.model.SecurityUser;

public class UserUtil {
	public static SysOrgPerson getUser() {
		Object person = SecurityContextHolder.getContext().getAuthentication()
				.getPrincipal();
		if (person instanceof SecurityUser) {
			return ((SecurityUser) person).getUser();
		} else if (person instanceof String && person.equals("anonymous")) {
			SysOrgPerson ps = new SysOrgPerson();
			ps.setFdName("匿名用户");
			ps.setFdLoginName("anonymous");
			SecurityUser se = new SecurityUser(ps,
					new ArrayList<GrantedAuthority>());
			return se.getUser();
		}
		return null;
	}
}
